package com.cn.customer.housekeeping.housekeepingb.biz.personcenter;


import com.cn.customer.housekeeping.housekeepingb.bean.BaseResp;
import com.cn.customer.housekeeping.housekeepingb.biz.BasePresenter;
import com.cn.customer.housekeeping.housekeepingb.bridge.BridgeFactory;
import com.cn.customer.housekeeping.housekeepingb.bridge.Bridges;
import com.cn.customer.housekeeping.housekeepingb.bridge.http.OkHttpManager;
import com.cn.customer.housekeeping.housekeepingb.capabilities.http.ITRequestResult;
import com.cn.customer.housekeeping.housekeepingb.capabilities.http.Param;
import com.cn.customer.housekeeping.housekeepingb.constant.URLUtil;

import java.io.File;


/**
 * <功能详细描述>
 */
public class InterfacePresenter extends BasePresenter<IUserLoginView> {

    public InterfacePresenter() {

    }




    /***
     * 验证码
     */
    public void getVerifyCode(String phone) {
        //网络层
        mvpView.showLoading();
        OkHttpManager httpManager = BridgeFactory.getBridge(Bridges.HTTP);
        httpManager.requestAsyncGetByTag(URLUtil.url_get_getVerifyCode, getName(), new ITRequestResult<BaseResp>() {
                    @Override
                    public void onCompleted() {
                        mvpView.hideLoading();
                    }

                    @Override
                    public void onSuccessful(BaseResp entity) {
                        mvpView.onSuccess(entity);

                    }

                    @Override
                    public void onFailure(BaseResp entity) {
                        mvpView.onError(entity);
                    }

                }, BaseResp.class, new Param("phone", phone)
        );
    }

    /***
     * 密码登录
     */
    public void getLogin(String phone ,String password) {
        //网络层
        mvpView.showLoading();
        OkHttpManager httpManager = BridgeFactory.getBridge(Bridges.HTTP);
        httpManager.requestAsyncPostByTag(URLUtil.url_get_login, getName(), new ITRequestResult<BaseResp>() {
                    @Override
                    public void onCompleted() {
                        mvpView.hideLoading();
                    }

                    @Override
                    public void onSuccessful(BaseResp entity) {
                        mvpView.onSuccess(entity);

                    }

                    @Override
                    public void onFailure(BaseResp entity) {
                        mvpView.onError(entity);
                    }

                }, BaseResp.class, new Param("phone", phone), new Param("password", password)
        );
    }
    /***
     * 注册
     */
    public void getRegist(String phone ,String verifycode,String password) {
        //网络层
        mvpView.showLoading();
        OkHttpManager httpManager = BridgeFactory.getBridge(Bridges.HTTP);
        httpManager.requestAsyncPostByTag(URLUtil.url_get_regist, getName(), new ITRequestResult<BaseResp>() {
                    @Override
                    public void onCompleted() {
                        mvpView.hideLoading();
                    }

                    @Override
                    public void onSuccessful(BaseResp entity) {
                        mvpView.onSuccess(entity);

                    }

                    @Override
                    public void onFailure(BaseResp entity) {
                        mvpView.onError(entity);
                    }

                }, BaseResp.class, new Param("phone", phone), new Param("verifycode", verifycode), new Param("password", password)
        );
    }





    /***
     * 首页服务类型
     *
     */

    public void getServicekind(String lat,String lon,String city) {
        //网络层
        mvpView.showLoading();
        OkHttpManager httpManager = BridgeFactory.getBridge(Bridges.HTTP);
        httpManager.requestAsyncPostByTag(URLUtil.url_get_servicekind, getName(), new ITRequestResult<BaseResp>() {
                    @Override
                    public void onCompleted() {
                        mvpView.hideLoading();
                    }

                    @Override
                    public void onSuccessful(BaseResp entity) {
                        mvpView.onSuccess(entity);

                    }

                    @Override
                    public void onFailure(BaseResp entity) {
                        mvpView.onError(entity);
                    }

                }, BaseResp.class, new Param("lat", lat), new Param("lon", lon), new Param("city", city)
        );
    }




    /***
     * 请求服务子类型
     */
    public void getSubServiceKind(String type ,String cityname) {
        //网络层
        mvpView.showLoading();
        OkHttpManager httpManager = BridgeFactory.getBridge(Bridges.HTTP);
        httpManager.requestAsyncPostByTag(URLUtil.url_get_getSubServiceKind, getName(), new ITRequestResult<BaseResp>() {
                    @Override
                    public void onCompleted() {
                        mvpView.hideLoading();
                    }

                    @Override
                    public void onSuccessful(BaseResp entity) {
                        mvpView.onSuccess(entity);

                    }

                    @Override
                    public void onFailure(BaseResp entity) {
                        mvpView.onError(entity);
                    }

                }, BaseResp.class, new Param("type", type), new Param("cityname", cityname)
        );
    }





    /***
     * 服务列表
     */
    public void getServicelist(String type ,String subtype,String page,String pagenum,String lat,String lon,String cityname) {
        //网络层
        mvpView.showLoading();
        OkHttpManager httpManager = BridgeFactory.getBridge(Bridges.HTTP);
        httpManager.requestAsyncPostByTag(URLUtil.url_get_getservicelist, getName(), new ITRequestResult<BaseResp>() {
                    @Override
                    public void onCompleted() {
                        mvpView.hideLoading();
                    }

                    @Override
                    public void onSuccessful(BaseResp entity) {
                        mvpView.onSuccess(entity);

                    }

                    @Override
                    public void onFailure(BaseResp entity) {
                        mvpView.onError(entity);
                    }

                }, BaseResp.class, new Param("type", type), new Param("subtype", subtype), new Param("page", page), new Param("pagenum", pagenum)
                , new Param("lat", lat), new Param("lon", lon), new Param("cityname", cityname)
        );
    }



    /***
     * 服务详情
     */
    public void getServicedetail(String serviceid ) {
        //网络层
        mvpView.showLoading();
        OkHttpManager httpManager = BridgeFactory.getBridge(Bridges.HTTP);
        httpManager.requestAsyncPostByTag(URLUtil.url_get_servicedetail, getName(), new ITRequestResult<BaseResp>() {
                    @Override
                    public void onCompleted() {
                        mvpView.hideLoading();
                    }

                    @Override
                    public void onSuccessful(BaseResp entity) {
                        mvpView.onSuccess(entity);

                    }

                    @Override
                    public void onFailure(BaseResp entity) {
                        mvpView.onError(entity);
                    }

                }, BaseResp.class, new Param("serviceid", serviceid)
        );
    }




    /***
     * 查询服务详情接口
     */
    public void getGetserviceinfo(String serviceid ) {
        //网络层
        mvpView.showLoading();
        OkHttpManager httpManager = BridgeFactory.getBridge(Bridges.HTTP);
        httpManager.requestAsyncPostByTag(URLUtil.url_get_getserviceinfoByid, getName(), new ITRequestResult<BaseResp>() {
                    @Override
                    public void onCompleted() {
                        mvpView.hideLoading();
                    }

                    @Override
                    public void onSuccessful(BaseResp entity) {
                        mvpView.onSuccess(entity);

                    }

                    @Override
                    public void onFailure(BaseResp entity) {
                        mvpView.onError(entity);
                    }

                }, BaseResp.class, new Param("serviceid", serviceid)
        );
    }





    /***
     * 第三方支付
     */
    public void getPay(String serviceid ,String orderid,String address,String lat,String lon,String hoursenum,String username
            ,String phone,String buytimestamp,String buycount,String comments) {
        //网络层
        mvpView.showLoading();
        OkHttpManager httpManager = BridgeFactory.getBridge(Bridges.HTTP);
        httpManager.requestAsyncPostByTag(URLUtil.url_get_pay, getName(), new ITRequestResult<BaseResp>() {
                    @Override
                    public void onCompleted() {
                        mvpView.hideLoading();
                    }

                    @Override
                    public void onSuccessful(BaseResp entity) {
                        mvpView.onSuccess(entity);

                    }

                    @Override
                    public void onFailure(BaseResp entity) {
                        mvpView.onError(entity);
                    }

                }, BaseResp.class, new Param("serviceid", serviceid), new Param("orderid", orderid), new Param("address", address)
                , new Param("lat", lat)      , new Param("lon", lon)      , new Param("hoursenum", hoursenum)      , new Param("username",username )
                , new Param("phone",phone ) , new Param("buytimestamp",buytimestamp ) , new Param("buycount", buycount) , new Param("comments",comments )
        );
    }










    /***
     * 获取腾讯云图片上传sign
     */
    public void getGetsign() {
        //网络层
        mvpView.showLoading();
        OkHttpManager httpManager = BridgeFactory.getBridge(Bridges.HTTP);
        httpManager.requestAsyncGetByTag(URLUtil.url_get_getsign, getName(), new ITRequestResult<BaseResp>() {
                    @Override
                    public void onCompleted() {
                        mvpView.hideLoading();
                    }

                    @Override
                    public void onSuccessful(BaseResp entity) {
                        mvpView.onSuccess(entity);

                    }

                    @Override
                    public void onFailure(BaseResp entity) {
                        mvpView.onError(entity);
                    }

                }, BaseResp.class
        );
    }



    /***
     * 批量上传图片
     */
    public void requestAsyncImgS(File[] files, String key, final String tag) {
        mvpView.showLoading();
        OkHttpManager httpManager = BridgeFactory.getBridge(Bridges.HTTP);
        httpManager.requestAsyncPost(URLUtil.url_get_TXyun, files, key,tag,new ITRequestResult<BaseResp>() {
            @Override
            public void onCompleted() {
                mvpView.hideLoading();
            }

            @Override
            public void onSuccessful(BaseResp entity) {
                entity.setTag(tag);
                mvpView.onSuccess(entity);
            }

            @Override
            public void onFailure(BaseResp entity) {
                mvpView.onError(entity);
            }

        }, BaseResp.class);
    }
}
